package com.koron.css2.newProjectCenter.impl.query;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.css2.ServerInterface;
import com.koron.css2.newProjectCenter.bean.query.PjQueryUserInfoBean;
import com.koron.css2.newProjectCenter.mapper.PjQueryUserInfoMapper;
import com.koron.css2.newProjectCenter.vo.query.PjQueryUserInfoVo;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import com.koron.util.Tools;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;
import java.util.Map;

/**
 * 用户档案查询入口
 */
public class PjQueryUserInfo implements ServerInterface {

    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        PjQueryUserInfoBean bean = JsonUtils.objectToPojo(req.getData(), PjQueryUserInfoBean.class);
        PjQueryUserInfoMapper mapper = factory.getMapper(PjQueryUserInfoMapper.class);
        PageHelper.startPage(bean.getPage(), bean.getPageCount());
        List<PjQueryUserInfoVo> list = mapper.getList(bean);
        if (!list.isEmpty()) {
            for (PjQueryUserInfoVo vo : list) {
                String businessType = vo.getBusinessType();
                if (businessType == null)
                    continue;
                switch (businessType) {
                    case "1": vo.setBusinessType("用水报装-居民");break;
                    case "2": vo.setBusinessType("水表迁移");break;
                    case "3": vo.setBusinessType("水表扩缩");break;
                    case "4": vo.setBusinessType("管道维修");break;
                    case "5": vo.setBusinessType("用水报装-企业");break;
                    default: vo.setBusinessType("其他");
                }
            }
        }

        PageInfo<PjQueryUserInfoVo> pageInfo = new PageInfo<>(list);
        MessageBean result = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功", PageInfo.class);
        result.setData(pageInfo);
        return result;
    }
}
